package com.bysj.service;

import com.bysj.dao.GoodsDao;
import com.bysj.entity.Goods;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    GoodsDao goodsDao;
    //添加商品
    @Override
    public void addGoods(Goods goods) {
        goodsDao.addGoods(goods);
    }
    //查询所有商品
    @Override
    public List<Goods> getAllGoods(Map map) {
        return goodsDao.getAllGoods(map);
    }
    //根据id查询商品
    @Override
    public List<Goods> getGoodsById(Integer id) {
        return goodsDao.getGoodsById(id);
    }
    //根据用户id查询商品
    @Override
    public List<Goods> getGoodsByUid(Integer id) {
        return goodsDao.getGoodsByUid(id);
    }
    //根据id删除商品
    @Override
    public void deleteGoodsById(Integer id) {
        goodsDao.deleteGoodsById(id);
    }
    //根据id修改商品
    @Override
    public void updateGoodsById(Goods goods) {
        goodsDao.updateGoodsById(goods);
    }
    //根据输入的文字查询相关商品
    @Override
    public List<Goods> getGoodsByWords(String searchwords) {
        return goodsDao.getGoodsByWords(searchwords);
    }
    //分页查询所有商品
    @Override
    public PageInfo<Goods> getAllGoodsByPage(Map map,int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Goods> goodsList = goodsDao.getAllGoods(map);
        PageInfo<Goods> pageInfo = new PageInfo<Goods>(goodsList);
        return pageInfo;
    }


}
